package hxy.dragon.secure

import org.junit.Assert.assertEquals
import org.junit.Test
import java.security.SecureRandom

class CryptoServiceAndroidTest {
    private val crypto = CryptoService()

    @Test
    fun encryptThenDecrypt_shouldReturnOriginalText_simpleAscii() {
        val message = "Hello, SecureWhisper!"
        val key = randomKey(32)
        val cipher = crypto.encrypt(message, key)
        val plain = crypto.decrypt(cipher, key)
        assertEquals(message, plain)
    }

    @Test
    fun encryptThenDecrypt_shouldReturnOriginalText_unicode() {
        val message = "你好，安全传输🔒🚀 — äöüß 字符混合"
        val key = randomKey(32)
        val cipher = crypto.encrypt(message, key)
        val plain = crypto.decrypt(cipher, key)
        assertEquals(message, plain)
    }

    private fun randomKey(length: Int): ByteArray {
        val key = ByteArray(length)
        SecureRandom().nextBytes(key)
        return key
    }
}


